package scc.project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scc.project.dao.SupplierDao;
import scc.project.entity.Supplier;
import scc.project.entity.vo.PageVo;

import java.util.List;

/**
 * @author 舒湖揭
 *         日期：2015-08-25
 */
@Service
public class SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    /**
     * 查询
     */
    public PageVo<Supplier> find(Integer page, String address, String supplierName) {
        PageVo<Supplier> pageVo = new PageVo<Supplier>(page);
        List<Supplier> suppliers = supplierDao.find(pageVo.getOffset(), pageVo.getRows(), address, supplierName);
        pageVo.setData(suppliers);
        pageVo.addParam("address", address);
        pageVo.addParam("name", supplierName);
        Long total = supplierDao.findTotal(address, supplierName);
        System.out.println("total = " + total);
        pageVo.setTotal(total);
        return pageVo;
    }


    /**
     * 添加
     */
    public boolean save(Supplier supplier) {
        return supplierDao.insert(supplier) > 0;
    }


    /**
     * 删除
     */
    public boolean deleteById(Long id) {
        return supplierDao.deleteById(id) > 0;
    }


    /**
     * 修改
     */
    public boolean updateById(Supplier supplier) {
        return supplierDao.updateById(supplier) > 0;
    }

    /**
     * 根据id查询数据
     */
    public Supplier get(Long id) {
        return supplierDao.selectById(id);
    }

    public List<Supplier> getAll() {
        return supplierDao.selectAll();
    }
}


